package com.example.demo2.mapper;

import com.example.demo2.entity.Comparison;
import com.example.demo2.entity.Feedback;
import com.example.demo2.entity.Program;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ComparisonMapper {
    @Select("select * from comparison where uID=#{uID}")
    List<Comparison> findComparisonByUID(@Param("uID") Integer uID);

    @Select("select * from program where pjId=#{pjID} and pgType=#{pgType} ")
    Program findComparisonBypjID(@Param("pjID") Integer pjID, @Param("pgType") String pgType);

    @Insert("insert into comparison(cpId,uID,pjId,startDate,cpStatus)" +
            "values(NULL,#{comparison.uID},#{comparison.pjId},#{comparison.startDate},0)")
    public int insertComparison(@Param("comparison") Comparison comparison);

    @Select("select * from comparison where uID=#{uID} and pjId=#{pjId}")
    public Comparison searchComparisonByPjId(@Param("uID") Integer uID, @Param("pjId") Integer pjId);

    @Select("select * from comparison where uID=#{uID} and startDate like #{query}")
    public List<Comparison> searchComparisonByStartDate(@Param("uID") Integer uID, @Param("query") String query);

    @Insert("INSERT INTO Comparison (uID, pjId, startDate, cpStatus, endDate, filePath) " +
            "VALUES (#{uId}, #{pjId}, #{startDate}, #{cpStatus}, #{endDate}, #{filePath})")
    int insertComparison1(Comparison comparison);

    @Update("UPDATE Comparison SET uID = #{uID}, pjId = #{pjId}, startDate = #{startDate}, " +
            "cpStatus = #{cpStatus}, endDate = #{endDate} WHERE cpId = #{cpId}")
    int updateComparison(Comparison comparison);

    @Delete("DELETE FROM Comparison WHERE cpId = #{cpId}")
    int deleteComparison(@Param("cpId") int cpId);

    @Select("SELECT c.cpId, u.uRealName, p.pjName, c.startDate, c.cpStatus, c.endDate" +
            " FROM comparison c"+
            " JOIN users u ON c.uID = u.uID " +
            " JOIN project p ON c.pjId = p.pjId"
    )
    List<Comparison> selectAllComparisons();

    @Select("SELECT * FROM Comparison WHERE cpId = #{cpId}")
    Comparison selectComparisonById(@Param("cpId") int cpId);

    //更新文件
    @Update("UPDATE program SET pgUrl = #{filePath} WHERE pjId = #{pjId} and pgType=3")
    int updateComparisonFilePath(@Param("pjId") Integer pjId, @Param("filePath") String filePath);


}
